<?php

/*
 * File  : aksi_produk.php
 * Table : produks, kategoris
 */
session_start();
//cek session

if (!$_SESSION["USRID"] AND !$_SESSION["USRPASS"]) {
    header("location: ../index.php");
    exit();
}
//end
?>

<?php

include "../../../library/fungsi.lib.php";

$module = $_GET["module"];
$opr = $_GET["opr"];

// hapus produk
if ($module == 'trans' AND $opr == 'hapus') {
    mysql_query("DELETE FROM tr_x WHERE trx_id='" . $_GET["id"] . "'");
    mysql_query("DELETE FROM tr_d WHERE trd_trx_id='" . $_GET["id"] . "'");

    header('location:' . URLHOST . 'cms/hansip.php?module=' . $module);
} // update status
elseif ($module == 'trans' AND $opr == 'update') {
    $status = $_POST ["in_transaksi_status_id"];
    $noresi = $_POST["in_no_resi"];
    $trx_id = $_POST["id"];
    $sql = "UPDATE tr_x SET trx_status='$status', trx_noresi='$noresi'
            WHERE trx_id='$trx_id'";

    //echo $sql;
    mysql_query($sql);
    if ($status == 2) {
        $sql_stok = mysql_query("select b.trd_produk_id as produk_id, b.trd_jumlah as produk_kurang
                                from tr_x a
                                left join tr_d b on (a.trx_id=b.trd_trx_id)
                                where a.trx_id='" . $trx_id . "'");
        while ($row = mysql_fetch_array($sql_stok)) {
            set_produk_stok($row["produk_id"], $row["produk_kurang"]);
            //echo $row["produk_id"] . " - " . $row["produk_kurang"];
        }
    }

    header('location:' . URLHOST . 'cms/hansip.php?module=' . $module);
}
?>
